package bakaLogin;

import pluginMain.BAKACraft;
import pluginMain.Configer;
import java.sql.*;
@Deprecated
@SuppressWarnings("unused")
public class BAKALogin {
	private boolean boolIsInitialized = false;
	private String strDBAddr = "127.0.0.1";
	private int intDBPort = 3306;
	private String strDBUser = "root";
	private String strDBPassword = "toor";
	private String strDBScheme = "user";
	//for default
	private final String strConfigFile = "BAKALogin.yml";
	private final String CONST_DB = "Database";
	private final String CONST_DB_ADDRESS = CONST_DB + ".Address";
	private final String CONST_DB_PORT = CONST_DB + ".Port";
	private final String CONST_DB_USER = CONST_DB + ".UserName";
	private final String CONST_DB_SCHEME = CONST_DB + ".Scheme";
	private final String CONST_DB_PASSWORD = CONST_DB + ".Password";
	
	private final String CONST_DB_CONN = "jdbc:mysql://";
	private Configer cConfig;
	
	
	private Connection connDBConnection;
	public BAKALogin() {
		cConfig = new Configer(BAKACraft.instance, strConfigFile);
		//connect to database
		strDBAddr = cConfig.getString(CONST_DB_ADDRESS);
		intDBPort = cConfig.getInt(CONST_DB_PORT);
		strDBUser = cConfig.getString(CONST_DB_USER);
		strDBPassword = cConfig.getString(CONST_DB_PASSWORD);
		strDBScheme = cConfig.getString(CONST_DB_SCHEME);
		
		try {
			Class.forName("com.mysql.jdbc.Driver");
			connDBConnection = DriverManager.getConnection(CONST_DB_CONN + strDBAddr + ":" + intDBPort + "//" + strDBScheme, strDBUser, strDBPassword);
		} catch (ClassNotFoundException e) {
			//Not installed the mysql driver
			boolIsInitialized = false;
			BAKACraft.getInstance().LOGCONSOLE("MySQL Driver was not install in you bukkit.");
			e.printStackTrace();
			return;
		} catch (SQLException e) {
			//Connection Error
			BAKACraft.getInstance().LOGCONSOLE("MySQL connect error");
			e.printStackTrace();
			return;
		}
		
		boolIsInitialized = true;
	}
	
	public BAKALogin getInstance()
	{
		return this;
	}
	
	public boolean getStatus()
	{
		return boolIsInitialized;
	}
}
